package com.example.demo.controller;

import com.example.demo.entity.CommonResult;
import com.example.demo.entity.purchasegoods;
import com.example.demo.service.PurchaseService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PurchaseController {
    @Autowired
    PurchaseService purchaseService;

    @PostMapping("/Purchase/Purchasegoods")
    @ResponseBody
    @ApiOperation(notes = "进货", value = "Purchasegoods")
    public CommonResult return_drugs(@ApiParam(name = "进货",required = true) @RequestBody purchasegoods purchasegoods){
        CommonResult addpurcahseimf = purchaseService.addpurcahseimf(purchasegoods);
        return addpurcahseimf;
    }
    @ResponseBody
    @GetMapping("/Purchase/get_Purchase_Onepage")
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "第几页，不传递默认第一页", dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "一页的数据量，默认10条数据 ",  dataType = "Integer", paramType = "query")})
    @ApiOperation(notes = "进货管理", value = "get_Purchase_Onepage")
    public CommonResult getOnepage( @RequestParam(value ="pageNum", defaultValue = "1")Integer pageNum,
                                    @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,String role){
        if (!role.equals("1")){
            return new CommonResult(201,"权限不够");
        }
        CommonResult commonResult = purchaseService.GetOnepagesPurcahse(pageNum, pageSize);
        return commonResult;
    }
    @ResponseBody  // 把返回的结果给浏览器
    @PostMapping("/Purchase/updatepurchasegoods")
    @ApiOperation(notes = "修改进货信息", value = "updatepurchasegoods")
    public CommonResult updatepurchasegoods(@ApiParam(name = "修改进货信息",required = true) @RequestBody purchasegoods purchasegoods){
        CommonResult commonResult = purchaseService.updatepurchasegoods(purchasegoods);
        return commonResult;
    }


    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键id"),
            @ApiImplicitParam(name = "drug_id",value = "药品id")}
    )
    @DeleteMapping("/Purchase/deletepurchasegoods")
    public CommonResult deletepurchasegoods(Integer id, String drug_id,String role) {
        if (!role.equals("1")){
            return new CommonResult(201,"您无法删除,权限不够");
        }
        CommonResult deletepurchasegoods = purchaseService.deletepurchasegoods(id, drug_id);
        return deletepurchasegoods;
    }


    @ResponseBody
    @GetMapping("/Purchase/selectpurchase")
    @ApiOperation(notes = "根据时间和名字查询", value = "selectpurchase")
    public CommonResult selectUser(String drug_id, String sale_time) {
        if (drug_id==null && sale_time==null){
            return new CommonResult(401,"不能空参查询");
        }
        CommonResult selectpurchase = purchaseService.selectpurchase(drug_id, sale_time);
        return selectpurchase;
    }


}
